package com.xiaode.controller.admin.example;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.core.paragetter.Para;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.Authority;
import com.xiaode.common.model.Admin;
import com.xiaode.common.model.dto.FindExampleDTO;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;

/**
 * 登录服务
 */
@Path("/aExample")
@Api("榜样相关")
@EnableCORS
public class ExampleController extends Controller {

    @Inject
    private ExampleService service;

    /**
     * 获取删除申请列表
     */
//    @ApiOper("获取删除申请列表")
//	@Authority(description = "删除榜样", permission = "admin:aExample:delExampleApplyPage", permissionParentName = "榜样模块", permissionName = "重要他人管理",type = 2)
//	public void delExampleApplyPage() throws Exception {
//		Ret ret = service.delExampleApplyPage();
//		renderJson(ret);
//    }
    
    /**
     * 删除
     */
	@ApiOper("删除榜样")
	@Authority(description = "删除榜样", permission = "admin:aExample:delExample", permissionParentName = "榜样模块", permissionName = "重要他人管理",type = 2)
	public void delExample(@NotEmpty @ApiPara(value = "exampleIds",notes = "榜样ID")String exampleIds) throws Exception {
		Admin admin = getAttr("admin");
		Ret ret = service.delExample(admin.getId(), exampleIds);
		renderJson(ret);
    }

	/**
	 * 查询榜样
	 */
	@ApiOper("查询榜样")
	@Before(ExampleParamValidator.class)
	@Authority(description = "查找榜样", permission = "admin:aExample:findExample", permissionParentName = "榜样模块", permissionName = "重要他人管理",type = 1)
	public void findExample(@ApiPara(value = "model",notes = "查询列") @Para("") FindExampleDTO model,
							@Size @ApiPara(value = "page",notes = "当前页")Integer page,
							@Size @ApiPara(value = "limit",notes = "每页大小")Integer limit)throws Exception{
		Admin admin = getAttr("admin");
		Kv kv = getAttr("kv");
		Ret ret = service.findExample(admin,model,kv,page,limit);
		renderJson(ret);
	}

	/**
	 * 修改榜样
	 */
	@ApiOper("修改榜样")
	@Authority(description = "修改榜样", permission = "admin:aExample:updateExample", permissionParentName = "榜样模块", permissionName = "重要他人管理",type = 2)
	public void updateExample(@ApiPara(value = "exId",notes = "榜样id")Integer exId,
			                  @ApiPara(value = "name",notes = "榜样名称")String name,
							  @ApiPara(value = "brief",notes = "简介")String brief,
							  @ApiPara(value = "characterType",notes = "榜样属性")Integer characterType,
							  @ApiPara(value = "reason",notes = "选择原因")String reason,
							  @Size @ApiPara(value = "pic",notes = "图片")String pic,
							  @ApiPara(value = "taskStr",notes = "榜样任务[{taskId:taskId,content:content}]")String taskStr)throws Exception{
		Admin admin = getAttr("admin");
		Ret ret = service.updateExample(admin,exId,name,characterType,brief,taskStr,reason,pic);
		renderJson(ret);
	}

	/**
	 * 添加榜样
	 */
	@ApiOper("添加榜样")
	@Authority(description = "添加榜样", permission = "admin:aExample:addExample", permissionParentName = "榜样模块", permissionName = "重要他人管理",type = 2)
    public void addExample(@Size(max = 20) @ApiPara(value = "name",notes = "榜样名称")String name,
						   @Size(max = 200) @ApiPara(value = "brief",notes = "简介")String brief,
						   @Size @ApiPara(value = "characterType", notes = "人物类型") Integer characterType,
						   @Size(max = 400) @ApiPara(value = "reason",notes = "选择原因")String reason,
						   @Size @ApiPara(value = "pic",notes = "图片")String pic,
						   @Size(max = 700) @ApiPara(value = "taskStr",notes = "榜样任务[content]")String taskStr)throws Exception{
		Admin admin = getAttr("admin");
		Ret ret = service.addExample(admin,name,brief,taskStr,characterType,reason,pic);
		renderJson(ret);
	}

	/**
	 * 审核榜样
	 */
	@ApiOper("审核榜样")
	@Authority(description = "审核榜样", permission = "admin:aExample:examineExample", permissionParentName = "榜样模块", permissionName = "重要他人管理",type = 2)
	public void examineExample(@Size @ApiPara(value = "exampleIds",notes = "榜样id")String exampleIds,
							   @Size @ApiPara(value = "state",notes = "审核状态")Integer state,
							   @ApiPara(value = "reason",notes = "原因")String reason)throws Exception{
		Admin admin = getAttr("admin");
		Ret ret = service.examineExample(admin,exampleIds,state,reason);
		renderJson(ret);
	}


}